package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.PageResult;
import com.woniu.pojo.MemberCard;
import com.woniu.mapper.MemberCardMapper;
import com.woniu.service.IMemberCardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.vo.MemberCardQueryVo;
import com.woniu.vo.QueryMemberCardVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xie
 * @since 2022-10-12
 */
@Service
public class MemberCardServiceImpl extends ServiceImpl<MemberCardMapper, MemberCard> implements IMemberCardService {

    @Autowired
    private MemberCardMapper mapper;

    @Override
    public PageResult queryByItemInPage(long currentPage, long pageSize, MemberCardQueryVo vo) {
        IPage page=new Page(currentPage,pageSize);
        IPage result=mapper.selectByItemInPage(page,vo);
        return new PageResult(result.getTotal(),result.getRecords());
    }

    @Override
    public QueryMemberCardVo queryById(String id) {
        return mapper.queryById(id);
    }

    @Override
    public int addMoney(Integer account, String id) {
        MemberCard memberCard = mapper.selectById(id);
        memberCard.setAccount(memberCard.getAccount()+account);
        int row = mapper.updateById(memberCard);
        return row;
    }
}
